#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/fcntl.h>
#include <unistd.h>

#define FILE_NAME "file1.txt"

int main() 
{
    int fd = open(FILE_NAME, O_RDONLY);
    if(fd == -1) 
    {
        perror("open");
        return 1;
    }

    char buf[1024];
    //C语言字符串以'\0'结尾，所以留一个位置来放置
    int ret = read(fd, buf, sizeof(buf) - 1);
    //read读到文件末尾返回0
    while(ret != 0)
    {
        buf[ret] = '\0';
        printf("%s", buf);
        ret = read(fd, buf, sizeof(buf) - 1);
    }

    close(fd);
}
